<?php
session_start();
header('Content-type:text/html;charset=utf-8');
include_once 'dbconfig.php';
include_once 'common.php';

if ($_POST) {
    if (isset($_POST['postType']) && $_POST['postType'] == 'register') {
        $name = $_POST['name'];
        $psw = md5($_POST['psw']);
        $login_time = time() * 1000;
        $selectSqlStr = 'select id from user where userName = "' . $name . '"';
        $res = $link->query($selectSqlStr);
        if ($res->num_rows > 0) {
            $msg = ['msg' => '“' . $name . '”该用户已注册', 'status' => 0];
            responseEvent($msg);
        }
        $insertSqlStr = 'INSERT INTO `jiulin`.`user` ( `userName`, `psw`, `login_time`) VALUES ( "' . $name . '", "' . $psw . '", "' . $login_time . '")';
        if ($link->query($insertSqlStr) === true) {
            $_SESSION['loginUserName'] = $name;
            $msg = ['msg' => '注册成功', 'status' => 1];
        } else {
            $msg = ['msg' => '注册失败', 'status' => 0];
        }
        responseEvent($msg);
    }
}